package logic

import (
	"context"

	"tianji-network/service/gateway/api/internal/svc"
	"tianji-network/service/gateway/api/internal/types"
	"tianji-network/service/satellite/rpc/satellite"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddSatelliteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddSatelliteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddSatelliteLogic {
	return &AddSatelliteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddSatelliteLogic) AddSatellite(req *types.AddReq) (resp *types.AddResp, err error) {
	r, err := l.svcCtx.SatelliteRpc.Add(l.ctx, &satellite.SatelliteOne{
		Id:        req.Id,
		Name:      req.Name,
		Status:    req.Status,
		Orbit:     req.Orbit,
		CosparId:  req.CosparId,
		LauchDate: req.LauchDate,
	})
	if err != nil {
		return nil, err
	}

	return &types.AddResp{
		Ok: r.Ok,
	}, nil
}
